import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store/index'
import Router from 'vue-router'
import './plugins/element.js'
import './assets/global.css'
import VueCropper from 'vue-cropper'
Vue.use(VueCropper)
Vue.use(Router)
const originalPush = Router.prototype.push
//修改原型对象中的push方法
Router.prototype.push = function push(location) {
   return originalPush.call(this, location).catch(err => err)
}
Vue.config.productionTip = false;
// 播放数量过滤器
Vue.filter('countFormat',function(count){
  if(typeof count === 'undefined') return count;
  if(count < 10000) return count
  else return Math.floor(count / 10000) + '万'
})
// 时间过滤器
Vue.filter('dateFormat',function(time){
  const t = new Date(time);
  let year = t.getFullYear()
  let mouth = t.getMonth() + 1
  let day = t.getDay()
  mouth = mouth < 10 ? '0' + mouth : mouth
  day = day < 10 ? '0' + day : day
  return year + '-' + mouth + '-' + day
})
// 歌曲时长过滤器
Vue.filter('timeFormat',function(time){
  let minutes = parseInt(time / 60); // 获取时长分钟
  let seconds = parseInt(time % 60); // 获取时长秒数
  seconds = seconds < 10 ? '0' + seconds : seconds // 秒
  minutes = minutes < 10 ? '0' + minutes : minutes
  return minutes + ':' + seconds
})
// Mv排行过滤器
Vue.filter('mvTopFormat',function(index){
  if(typeof index === 'undefined') return;
  return index < 10 ? '0' + index  : index ;
})
Vue.prototype.$scrollTo = (x = 0, y = 0, type = 'smooth') => {
	window.scrollTo({
		top: x,
		left: y,
		behavior: type // 滚动行为：smooth平滑滚动，instant瞬间滚动，默认值auto，等同于instant
	})
}
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
